package com.lc.user.express.ordering;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.lc.user.express.BaseSecondActivity;
import com.lc.user.express.R;
import com.lc.user.express.httpserver.Net;


/**
 * Created by Administrator on 2016/3/23. 具体家具名称
 */
public class FunitureNameActivity extends BaseSecondActivity {
    private WebView webView;
    private TextView tv_price;//规格价格
    private TextView tv_content;//图文详情
    private TextView tv_factoryinfo;//厂家介绍
    private TextView tv_payinfo;//平台支付

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_funiture_name);
        setTitle(getIntent().getStringExtra("title"));
        initView();
    }

    private void initView() {
        ((TextView) findViewById(R.id.tv_public)).setOnClickListener(this);
        tv_price = (TextView) findViewById(R.id.tv_price);
        tv_price.setOnClickListener(this);
        tv_content = (TextView) findViewById(R.id.tv_content);
        tv_content.setOnClickListener(this);
        tv_factoryinfo = (TextView) findViewById(R.id.tv_factoryinfo);
        tv_factoryinfo.setOnClickListener(this);
        tv_payinfo = (TextView) findViewById(R.id.tv_payinfo);
        tv_payinfo.setOnClickListener(this);
        webView = (WebView) findViewById(R.id.web);
        webView.setVerticalScrollbarOverlay(true); //指定的垂直滚动条有叠加样式
        WebSettings wSet = webView.getSettings();
        wSet.setJavaScriptEnabled(true);
        wSet.setBuiltInZoomControls(true);
        wSet.setLoadWithOverviewMode(true);
        wSet.setUseWideViewPort(true);
        wSet.setLoadWithOverviewMode(true);
        wSet.setSupportZoom(true);

        initWebView(Net.WEB_SPECIPRICE);
        setButtonView(1);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_public:
                Bundle bundle = new Bundle();
                bundle.putString("title", getIntent().getStringExtra("title"));
                bundle.putString("goodsid", getIntent().getStringExtra("goodsid"));
                show(FuniturePayActivity.class, bundle);
                break;
            case R.id.tv_price:
                initWebView(Net.WEB_SPECIPRICE);
                setButtonView(1);
                break;
            case R.id.tv_content:
                initWebView(Net.WEB_CONTENT);
                setButtonView(2);
                break;
            case R.id.tv_factoryinfo:
                initWebView(Net.WEB_FACTRYINFO);
                setButtonView(3);
                break;
            case R.id.tv_payinfo:
                initWebView(Net.WEB_PAYINFO);
                setButtonView(4);
                break;
            default:
                break;
        }
    }

    private void initWebView(String webUrl) {
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
            }
        });
        if (webView != null) {
//            Logger.print("lll", "==" + Net.SERVER + webUrl + "?goodid=" + getIntent().getStringExtra("goodsid"));
            webView.loadUrl(Net.SERVER + webUrl + "?goodid=" + getIntent().getStringExtra("goodsid"));
        }
    }

    private void setButtonView(int flags) {
        if (flags == 1) {
            tv_price.setSelected(true);
            tv_content.setSelected(false);
            tv_payinfo.setSelected(false);
            tv_factoryinfo.setSelected(false);
        } else if (flags == 2) {
            tv_price.setSelected(false);
            tv_content.setSelected(true);
            tv_payinfo.setSelected(false);
            tv_factoryinfo.setSelected(false);
        } else if (flags == 3) {
            tv_price.setSelected(false);
            tv_content.setSelected(false);
            tv_payinfo.setSelected(false);
            tv_factoryinfo.setSelected(true);
        } else if (flags == 4) {
            tv_price.setSelected(false);
            tv_content.setSelected(false);
            tv_payinfo.setSelected(true);
            tv_factoryinfo.setSelected(false);
        }
    }
}
